import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import 'package:get/get.dart';
import 'package:smart_translator/app/event/DataCallBack.dart';
import 'package:smart_translator/app/views/controller/IndexViewController.dart';

import '../../../db/database.dart';
import '../../../routes/app_pages.dart';
import '../../../style/app_colors.dart';
import '../../../style/widget_style.dart';
import '../../../widgets/AppHeader.dart';
import '../../../widgets/CommonWidgets.dart';
import '../controllers/translate_result_controller.dart';

class TranslateResultView extends GetView<TranslateResultController> {
  const TranslateResultView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Stack(
          children: [
            Container(
              child: SvgPicture.asset(
                "assets/images/header_part_bg.svg",
                width: Get.width,
              ),
            ),

            Obx(()=>Container(
              width: Get.width,
              margin: EdgeInsets.only(top: 35.h),
              padding: EdgeInsets.all(20.w),
              child: ListView(
                controller: controller.listScroll,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () {
                          controller.chooseFromLanguages();
                        },
                        child: Container(
                          width: 127.w,
                          height: 48.h,
                          padding: EdgeInsets.all(8.w),
                          decoration: BoxDecoration(
                            boxShadow: [
                              CommonWidgets.getBoxShadow(),
                            ],
                            color:Colors.white,
                            borderRadius: BorderRadius.circular(8), // Optional: add border radius
                          ),
                          child: Center(
                            child: Text('${controller.audioService.fromLanFlagDisplay.value}',style: AppStyleThemeData.normal_bold,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ),
                      ),
                      InkWell(onTap: () {
                           controller.exchangeLanguages();
                      },
                      child: Container(
                        height: 48.h,
                        padding: EdgeInsets.all(18.w),
                        decoration: BoxDecoration(
                          boxShadow: [
                            CommonWidgets.getBoxShadow(),
                          ],
                          color:Colors.white,
                          borderRadius: BorderRadius.circular(8), // Optional: add border radius
                        ),
                        child: Image.asset('assets/images/icon_index_lang_exchange.png',width: 20.w,height: 20.h,),
                      ),),
                      InkWell(
                        onTap: () {
                          controller.chooseToLanguages();
                        },
                        child: Container(
                          width: 127.w,
                          height: 48.h,
                          padding: EdgeInsets.all(8.w),
                          decoration: BoxDecoration(
                            boxShadow: [
                              CommonWidgets.getBoxShadow(),
                            ],
                            color:Colors.white,
                            borderRadius: BorderRadius.circular(8), // Optional: add border radius
                          ),
                          child: Center(
                            child: Text('${controller.audioService.toLanFlagDisplay.value}',style: AppStyleThemeData.normal_bold,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                  SizedBox(height: 16.h),
                  Container(
                    height: 141.h,
                    decoration: BoxDecoration(
                      boxShadow: [
                        CommonWidgets.getBoxShadow(),
                      ],
                      color:  Colors.white,
                      borderRadius: BorderRadius.circular(8), // Optional: add border radius
                    ),
                    child: Stack(
                      children: [
                        // 输入框
                        GestureDetector(
                          onTap: () {
                            IndexViewController indexController = Get.find<IndexViewController>();
                            indexController.stopAudioPlay();
                            Get.back();
                          },
                          child: Container(
                            width: Get.width,
                            margin: EdgeInsets.only(top: 25.h),
                            padding: EdgeInsets.only(left: 16.w,top: 12.h,right: 16.w,bottom: 12.h),
                            child:  Text(
                              controller.audioService.indexPageFinalFromLanguage.value,
                              maxLines: 8,
                              style: TextStyle(fontSize: 15.sp),
                            ),
                          ),
                        ),
                        // 记录按钮
                        Positioned(
                          left: 16.w,
                          top: 12.h,
                          child: Row(
                            children: [
                              Text(controller.audioService.fromLanFlagDisplay.value, style: AppStyleThemeData.HINT_TEXT_STYLE),
                            ],
                          ),
                        ),
                        Positioned(
                          right: 16.w,
                          top: 5.h,
                          child: InkWell(
                            onTap: () {
                              // controller.pastFromOtherSource();
                              controller.audioSpeakerSource();
                            },
                            child: Container(
                                padding: EdgeInsets.all(10.w),
                                child: Image.asset('assets/images/icon_audio_play_btn.png',width: 16.w,height: 16.h)
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(height: 16.h),
                  Container(
                    height: 272.h,
                    decoration: BoxDecoration(
                      boxShadow: [
                        CommonWidgets.getBoxShadow(),
                      ],
                      color:  Colors.white,
                      borderRadius: BorderRadius.circular(8), // Optional: add border radius
                    ),
                    child: Stack(
                      children: [
                        // 输入框
                        Container(
                          width: Get.width,
                          margin: EdgeInsets.only(top: 25.h),
                          padding: EdgeInsets.only(left: 16.w,top: 12.h,right: 16.w,bottom: 12.h),
                          child:  Text(
                            controller.audioService.indexPageFinalToLanguage.value,
                            maxLines: 8,
                            style: TextStyle(fontSize: 15.sp),
                          ),
                        ),
                        Positioned(
                          left: 16.w,
                          top: 12.h,
                          child: Row(
                            children: [
                              Text(controller.audioService.toLanFlagDisplay.value, style: AppStyleThemeData.HINT_TEXT_STYLE),
                            ],
                          ),
                        ),

                        // 记录按钮
                        Positioned(
                          left: 16.w,
                          bottom: 12.h,
                          child: InkWell(
                            onTap: () {
                              controller.cleanContent();
                            },
                            child: Container(
                              padding: EdgeInsets.all(10.w),
                              child: Text('清除', style: TextStyle(
                                  color: AppColors.app_base_theme_color,
                                  fontSize: 14.sp,
                                  fontWeight: FontWeight.bold
                              )),
                            ),
                          ),
                        ),
                        Positioned(
                          right: 50.w,
                          bottom: 12.h,
                          child: InkWell(
                            child: Container(
                              padding: EdgeInsets.all(10.w),
                              child: Image.asset('assets/images/icon_copy_something.png',width: 16.w,height: 16.h),
                            ),
                            onTap: () {
                              controller.copySomething();

                            },
                          ),
                        ),
                        Positioned(
                          right: 16.w,
                          bottom: 12.h,
                          child: InkWell(
                            child: Container(
                              padding: EdgeInsets.all(10.w),
                              child: Image.asset('assets/images/icon_full_screen.png',width: 16.w,height: 16.h),
                            ),
                            onTap: () {
                              Get.toNamed(Routes.TRANSLATE_RESULT_LANDSCAPE,parameters: {
                                'source': controller.audioService.indexPageFinalFromLanguage.value,
                                'target': controller.audioService.indexPageFinalToLanguage.value
                              });
                            },
                          ),
                        ),
                        Positioned(
                          right: 16.w,
                          top: 5.h,
                          child: InkWell(
                            onTap: () {
                              controller.audioSpeakerTarget();
                            },
                            child: Container(
                                padding: EdgeInsets.all(10.w),
                                child: Image.asset('assets/images/icon_audio_play_btn.png',width: 16.w,height: 16.h)
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(height: 20.h,),
                  Row(
                    children: [
                      Text('最近',style: AppStyleThemeData.HINT_TEXT_STYLE,)
                    ],
                  ),
                  SizedBox(height: 10.h,),
                  Container(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: controller.historyWigetItem.value,
                      )
                  ),

                ],
              ),
            )),
            Positioned(
                top: 0,
                child:
                  AppHeader.obtainHeaderWithoutTitleAndRightPart(callback: DataCallBack(
                      businessCallBack: (v) {
                        Get.offAllNamed(Routes.HOME);

                      }
                  ))
            )
          ],
        )
    );
  }

}
